package com.hancai.servlet;

import com.hancai.entity.Employee;
import com.hancai.service.EmployeeService;
import com.hancai.service.impl.EmployeeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 涵菜
 * @version 1.0
 */
@WebServlet(urlPatterns = "/EmployeeLoginServlet")
public class EmployeeLoginServlet extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1,接收页面的数据
        String ename = req.getParameter("ename");
        String pwd = req.getParameter("pwd");
        //2，数据的处理-返回结果
        EmployeeService employeeService = new EmployeeServiceImpl();
        Employee loginEmp = employeeService.login(ename, pwd);
        //3，跟据结果给用户做出响应
        if(loginEmp!=null) {
            resp.sendRedirect(req.getContextPath()+"/index.html");
        }else {
            req.setAttribute("msg","登陆失败");
            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        }

    }
}
